// 分页查询包装函数
export const setPageInfo = (form: any, e: any) => {
    if (e) {
        if (e['page']) {
            form.page = e['page']
        }
        if (e['pageSize']) {
            form.pageSize = e['pageSize']
        }
        if (e['prop']) {
            switch (e['order']) {
                case 'ascending':
                    form.ascs = e['prop']
                    form.descs = ''
                    break
                case 'descending':
                    form.ascs = ''
                    form.descs = e['prop']
                    break
                default:
                    form.ascs = ''
                    form.descs = ''
            }
        }
    }
}

/**
 * 字符串转json
 * @param str 字符串
 */
export const convertStrToStr = (str: any) => {
    try {
        return JSON.parse(str);
    } catch (e) {
        return str;
    }
}

// 日期快捷选择
export const shortcuts = [
    {
        text: 'Last week',
        value: () => {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - (3600 * 1000 * 24 * 7))
            return [start, end]
        },
    },
    {
        text: 'Last month',
        value: () => {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - (3600 * 1000 * 24 * 30))
            return [start, end]
        },
    },
    {
        text: 'Last 3 months',
        value: () => {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - (3600 * 1000 * 24 * 90))
            return [start, end]
        },
    },
]